package common;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2020-07-16
 * Time: 14:28
 *
 * @author zyh
 */
public class ConnectWatch implements Watcher {


    private CountDownLatch countDownLatch;

    ConnectWatch(CountDownLatch connectWatch){
        this.countDownLatch = connectWatch;
    }


    @Override
    public void process(WatchedEvent event) {
        Event.KeeperState state = event.getState();

        switch (state) {
            case Unknown:
                break;
            case Disconnected:
                System.out.println("Disconnected");
                break;
            case NoSyncConnected:
                break;
            case SyncConnected:
                this.countDownLatch.countDown();
                System.out.println("SyncConnected");
                break;
            case AuthFailed:
                break;
            case ConnectedReadOnly:
                break;
            case SaslAuthenticated:
                break;
            case Expired:
                break;
            case Closed:
                break;
            default:
                break;
        }
    }
}
